package com.example.yiwei.crm.view.activity.customerActivity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.PopupMenu;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.dao.customerDao;
import com.example.yiwei.crm.dao_impl.customerDaoImpl;
import com.example.yiwei.crm.data.GetContact;
import com.example.yiwei.crm.data.GetCustumer;
import com.example.yiwei.crm.entity.ApointmentEntity;
import com.example.yiwei.crm.entity.ContactMessageEntity;
import com.example.yiwei.crm.entity.CustomerMessageEntity;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;
import com.example.yiwei.crm.view.activity.menuActivity.HomeActivity;
import com.example.yiwei.crm.view.frament.customerDetailedMenuPackage.BaseFragment;
import com.example.yiwei.crm.view.frament.customerDetailedMenuPackage.OtherBaseFragment;
import com.example.yiwei.crm.view.frament.customerDetailedMenuPackage.OtherFragment;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CustomerDetailedMessageActivity extends AppCompatActivity implements View.OnClickListener {
    ImageView fabIconStar;
    FloatingActionMenu leftCenterMenu;
    //    FloatingActionMenu leftCenterMenu1;
    FloatingActionButton leftCenterButton;
    FloatingActionButton leftCenterButton1;
    ImageView lcIcon1 ;
    ImageView lcIcon2 ;
    ImageView lcIcon3 ;
    ImageView lcIcon4 ;
    private PopupWindow mPopWindow;
    private ImageView img_shouye,img_more1,img_guanzhu;
    FragmentManager manager;
    Intent intent;
    List<CustomerMessageEntity> customerMessageEntityList;
    //声明碎片
    Fragment fragment_base, fragment_other, fragment_return_visit_record;
    Button button1, button2, button4;
    private PopupMenu popupMenu;
    private Menu menu;
    CustomerMessageEntity updateCustomer;
    ContactMessageEntity contact;
    List<ContactMessageEntity> contacts;
    ContactMessageEntity upadateContact;
    CustomerMessageEntity customer;
    private static final String Tag = "update";
    TextView txt_title_name;
    boolean ButtonTag2 = false;
    boolean ButtonTag1 = false;
    boolean ButtonTag4 = false;
    int manger_id;
    private ImageView img_call,img_message;
    ApointmentEntity appointmentEntity;
    String[] sex;
    AlertDialog.Builder builder;
    int number;
    private  Button btn_appointment,btn_daoyuan,btn_treat,btn_member;
    String phone_number;
    private TextView txt_attention;
    private String []date;
    public String[]theme;
    public static CustomerDetailedMessageActivity a;
    private List<CustomerMessageEntity> list;
    int communicate_id;
    ImageView img_back;
    SharedPreferences sp;
    JSONObject json1;
    ImageView im_update;
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer_detailed_message);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        txt_title_name = (TextView) findViewById(R.id.usermess_user_name);
        img_shouye= (ImageView) findViewById(R.id.simple_coording_img_shouye);
        img_guanzhu= (ImageView) findViewById(R.id.detailed_customer_guanzhu);
        img_more1= (ImageView) findViewById(R.id.customer_img_more);
        im_update = (ImageView) findViewById(R.id.detailed_customer_img_update);
        img_back = (ImageView) findViewById(R.id.usermess_back_btn);
        img_call= (ImageView) findViewById(R.id.customer_detailed_img_call);
        btn_appointment= (Button) findViewById(R.id.customer_detailed_btn_appointment);
        btn_daoyuan= (Button) findViewById(R.id.customer_detailed_btn_daoyuan);
        btn_member= (Button) findViewById(R.id.customer_detailed_btn_member);
        btn_treat= (Button) findViewById(R.id.customer_detailed_btn_treat);
        txt_attention= (TextView) findViewById(R.id.customer_detailed_txt_attention);
        img_message= (ImageView) findViewById(R.id.customer_detailed_img_message);
        customer = GetCustumer.get();
        contact = GetContact.get();
        addXuanFu1();
        img_more1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showPopupWindow();
            }
        });
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        img_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                        contacts = new ArrayList<>();
                        contacts.add(contact);
                        List<String> names = new ArrayList<>();

                            for (int i = 0; i < contacts.size(); i++) {
                                names.add(contacts.get(i).getContact_name());

                        }
                        sex = names.toArray(new String[names.size()]);

                                if (contacts.equals("")){
                                    Toast.makeText(CustomerDetailedMessageActivity.this, "无联系人号码,请新建联系人！", Toast.LENGTH_SHORT).show();
                                }else {
                                    showMessageDialog();
                                }





            }
        });
        img_shouye.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(CustomerDetailedMessageActivity.this, HomeActivity.class);
                intent.putExtra("tag","back");
                startActivity(intent);
                finish();
            }
        });

        img_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                        contacts = new ArrayList<ContactMessageEntity>();
                        contacts.add(contact);
                        List<String> names = new ArrayList<String>();
                                for (int i = 0; i < contacts.size(); i++) {
                                    names.add(contacts.get(i).getContact_name());

                        }
                        sex = names.toArray(new String[names.size()]);

                                if (contacts.equals("")){
                                    Toast.makeText(CustomerDetailedMessageActivity.this, "无联系人号码,请新建联系人！", Toast.LENGTH_SHORT).show();
                                }else {
                                    showContactDialog();
                                }




            }
        });
        txt_title_name.setText(customer.getClient_name());
        if(customer.getIs_attention()==1){
            txt_attention.setText("已关注");
            img_guanzhu.setImageResource(R.drawable.yiguanzhu1);
        }else{
            img_guanzhu.setImageResource(R.drawable.weiguanzhu1);
            txt_attention.setText("未关注");
        }
        final int appointment=customer.getFollw_state();
        if (appointment==1){
            btn_appointment.setText("已预约");
        }else{
            btn_appointment.setText("未预约");
        }
        intent = getIntent();
        manager = getSupportFragmentManager();
        //将字符串改为int型
        //初始化按钮
        button1 = (Button) findViewById(R.id.mess_frame_callback);
        button2 = (Button) findViewById(R.id.mess_frame_basemess);
        button4 = (Button) findViewById(R.id.mess_frame_other);
        //初始化碎片
        fragment_base = new BaseFragment();
        fragment_other = new OtherFragment();
        fragment_return_visit_record = new OtherBaseFragment();
        OnClick(button2);
        popupMenu = new PopupMenu(this, findViewById(R.id.UserMess_more_btn));
        menu = popupMenu.getMenu();
        final MenuInflater inflater = getMenuInflater();
        //设置menu界面为res/menu/menu.xml
        if ("kehuchi".equals(getIntent().getStringExtra("kehuchiTag"))) {
            inflater.inflate(R.menu.menu, menu);
        }else if ("lqkh".equals(getIntent().getStringExtra("tag"))){
            inflater.inflate(R.menu.menu3, menu);
        }
        else{
            inflater.inflate(R.menu.munu2, menu);
        }
        im_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonTag2){
                    Intent intent = new Intent(CustomerDetailedMessageActivity.this,BaseUpdateActivity.class);
                    startActivity(intent);
                }else if (ButtonTag1){
                    Intent intent = new Intent(CustomerDetailedMessageActivity.this,OtherBaseUpdateActivity.class);
                    startActivity(intent);
                }else if (ButtonTag4){
                    Intent intent = new Intent(CustomerDetailedMessageActivity.this,ContactUpdateActivity.class);
                    startActivity(intent);
                }
            }
        });
        lcIcon4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CustomerDetailedMessageActivity.this,CustomerAppointmentAcitity.class);
                intent.putExtra("ID",customer.getClient_id());
                intent.putExtra("customer","customer");
                startActivity(intent);
            }
        });
        lcIcon3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(CustomerDetailedMessageActivity.this,CustomerAddCommActivity.class);
                intent.putExtra("customerid",customer.getClient_id());
                intent.putExtra("TAG","detil");
                startActivity(intent);
            }
        });

    }

    public void showMessageDialog(){
        //    设置一个单项选择下拉框
        /**
         * 第一个参数指定我们要显示的一组下拉单选框的数据集合
         * 第二个参数代表索引，指定默认哪一个单选框被勾选上，1表示默认'女' 会被勾选上
         * 第三个参数给每一个单选项绑定一个监听器
         */
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.custom_dialog));
        builder.setTitle("请选择联系人");
        builder.setSingleChoiceItems(this.sex, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                number=which;
                String name=sex[which];
                if (name.equals(contacts.get(which).getContact_name())){
                    phone_number=contacts.get(which).getFirst_contact_mobile_phone();
                    messageDialog();
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }
    public void showContactDialog() {
        //    设置一个单项选择下拉框
        /**
         * 第一个参数指定我们要显示的一组下拉单选框的数据集合
         * 第二个参数代表索引，指定默认哪一个单选框被勾选上，1表示默认'女' 会被勾选上
         * 第三个参数给每一个单选项绑定一个监听器
         */
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.custom_dialog));
        builder.setTitle("请选择联系人");
        builder.setSingleChoiceItems(this.sex, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                number=which;
                String name=sex[which];
                if (name.equals(contacts.get(which).getContact_name())){
                    phone_number=contacts.get(which).getFirst_contact_mobile_phone();
                    contactDialog();
                    dialog.dismiss();
                }
            }
        });
        builder.show();
    }
    public void contactDialog(){
        builder = new AlertDialog.Builder(new ContextThemeWrapper(CustomerDetailedMessageActivity.this, R.style.custom_dialog));
        builder.setTitle("您确定要拨打电话吗？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + phone_number);
                intent.setData(data);
                startActivity(intent);
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }

    public void  messageDialog(){
        builder = new AlertDialog.Builder(new ContextThemeWrapper(CustomerDetailedMessageActivity.this, R.style.custom_dialog));
        builder.setTitle("您确定要发送短信吗？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+phone_number));
                        startActivity(intent);

            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.show();
    }
    public void OnClick(View view) {
        switch (view.getId()){
            case R.id.mess_frame_callback:
                ButtonTag2=false;
                ButtonTag1 = true;
                ButtonTag4 = false;
                button1.setBackgroundColor(Color.parseColor("#FFFFFF"));
                button2.setBackgroundColor(Color.parseColor("#E1E8ED"));
                button4.setBackgroundColor(Color.parseColor("#E1E8ED"));
                manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_return_visit_record).commit();
                break;
            case R.id.mess_frame_basemess:
                ButtonTag1 = false;
                ButtonTag2=true;
                ButtonTag4 = false;
                button1.setBackgroundColor(Color.parseColor("#E1E8ED"));
                button2.setBackgroundColor(Color.parseColor("#FFFFFF"));
                button4.setBackgroundColor(Color.parseColor("#E1E8ED"));
                manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_base).commit();
                break;
            case R.id.mess_frame_other:
                ButtonTag1 = false;
                ButtonTag2=false;
                ButtonTag4 = true;
                button1.setBackgroundColor(Color.parseColor("#E1E8ED"));
                button2.setBackgroundColor(Color.parseColor("#E1E8ED"));
                button4.setBackgroundColor(Color.parseColor("#FFFFFF"));
                manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_other).commit();
                break;
            case R.id.UserMess_more_btn:
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(new ContextThemeWrapper(CustomerDetailedMessageActivity.this, R.style.custom_dialog));
                builder.setTitle("您确定要删除吗？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                SC sc = new SC();
                                JSONObject object = sc.storage(sp);
                                try {
                                    object.put("KAA01", customer.getClient_id());
                                    String json = object.toString();
                                    String result = NetWorkUtils.getCount(baseClass.delete_coor_customer_URL, json);
                                    json1 = new JSONObject(result);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (json1.has("flag")) {

                                            try {
                                                int a = json1.getInt("flag");

                                                if (a == 0) {
                                                    boolean b = json1.getBoolean("ifsuccess");
                                                    if (b) {
                                                                finish();
                                                    } else {
                                                        Toast.makeText(CustomerDetailedMessageActivity.this, "删除失败", Toast.LENGTH_SHORT).show();
                                                    }
                                                } else {
                                                    Toast.makeText(CustomerDetailedMessageActivity.this, "该客户有预约信息，不允许删除", Toast.LENGTH_SHORT).show();
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }

                                        } else {
                                            Toast.makeText(CustomerDetailedMessageActivity.this, "连接数据失败", Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                });
                            }
                        }).start();
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();
                break;
            case R.id.usermess_back_btn:
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        customerDao customerDao=new customerDaoImpl();
                        customerMessageEntityList=new ArrayList<CustomerMessageEntity>();
                        customerMessageEntityList=customerDao.querySimpleCustomerMessage(baseClass.find_all_customer_url,null);
                        if (customerMessageEntityList!=null){
                            finish();
                        }
                    }
                }).start();
                break;

        }
    }
    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.customer_apo:
                Intent intent2 = new Intent(CustomerDetailedMessageActivity.this,SimpleCustomerApoActivity.class);
                intent2.putExtra("customerid",customer.getClient_id());
                startActivity(intent2);
                break;
            case R.id.custom_comm_log:
                Intent intent = new Intent(CustomerDetailedMessageActivity.this,CustomerSimpleCommunicateLogActivity.class);
                intent.putExtra("customerid",customer.getClient_id());
                startActivity(intent);
                break;
            case R.id.customer_team:
                Intent intent3=new Intent(CustomerDetailedMessageActivity.this,TeamMembersActivity.class);
                intent3.putExtra("customerid",customer.getClient_id());
                startActivity(intent3);
                break;
            case R.id.customer_operation_log:
                Intent intent1 = new Intent(CustomerDetailedMessageActivity.this,CustomerOperationLogActivity.class);
                intent1.putExtra("customerid",customer.getClient_id());
                startActivity(intent1);
                break;
        }
    }
    public void  addXuanFu1(){
        /**
         * 一个FloatingActionButton有一个FloatingActionMenu，FloatingActionMenu添加动画弹出的子菜单。
         * FloatingActionButton的按钮点击事件将触发、弹出FloatingActionMenu中包含的子菜单。
         * FloatingActionMenu使用attachTo方法附着在一个FloatingActionButton上。
         * FloatingActionMenu在attachTo到一个FloatingActionButton后，两者之间发生关联。
         * FloatingActionMenu在添加子菜单时候，首先需要一个SubActionButton.Builder，该SubActionButton.
         * Builder通过setContentView(ImageView
         * image).build()把一个ImageView创建生产一个SubActionButton ,
         * 然后通过FloatingActionMenu.Builder的add方法把前面生成的SubActionButton添加进去。
         *
         *
         * 按钮的旋转动画在onMenuOpened和onMenuClosed中做。
         *
         */
        WindowManager wm = (WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);

        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();
        //按钮的大小
        int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size1);
        //距离下边的长度
        int redActionButtonMargin = 7;
        //距离右边的长度
        int redActionButtonMarginRight = width/2-getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size)/2;
        //按钮中内容的大小
        int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
        int redActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.red_action_button_content_margin);
        //弹出圆弧的半径
        int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius3);
        int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
        int blueSubActionButtonContentMargin = getResources()
                .getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);

        fabIconStar = new ImageView(this);
        //按钮中的图片
        fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.plus5));

        FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(redActionButtonSize,
                redActionButtonSize);
        starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMarginRight,
                redActionButtonMargin);
        fabIconStar.setLayoutParams(starParams);

        FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(
                redActionButtonContentSize, redActionButtonContentSize);
        fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin,
                redActionButtonContentMargin, redActionButtonContentMargin);

        leftCenterButton = new FloatingActionButton.Builder(this)
                .setContentView(fabIconStar, fabIconStarParams)
                .setBackgroundDrawable(R.drawable.button_action_red_selector)// 设置变化时的背景色
                .setPosition(FloatingActionButton.POSITION_BOTTOM_RIGHT)// 靠近右边和下边
                .setLayoutParams(starParams).build();

        // Set up customized SubActionButtons for the right center menu
        SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
        lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));

        FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT);
        blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin,
                blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
        lCSubBuilder.setLayoutParams(blueContentParams);
        // Set custom layout params
        FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize,
                blueSubActionButtonSize);
        lCSubBuilder.setLayoutParams(blueParams);

//        ImageView lcIcon1 = new ImageView(this);
//        ImageView lcIcon2 = new ImageView(this);
//        ImageView lcIcon3 = new ImageView(this);
//
//        lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.u116));
//        lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.u117));
//        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.u118));
        //添加按钮
        lcIcon3 = new ImageView(this);
        lcIcon4 = new ImageView(this);

//         lcIcon4 = new TextView(this);
        lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.u1191));
        lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.u1192));
//        lcIcon4.setText("选择部门");

        // Build another menu with custom options
        leftCenterMenu = new FloatingActionMenu.Builder(this)
                .addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build())
                .addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build())
                .setRadius(redActionMenuRadius).setStartAngle(240).setEndAngle(300).attachTo(leftCenterButton).build();



    }
    private void showPopupWindow() {
        View contentView = LayoutInflater.from(CustomerDetailedMessageActivity.this).inflate(
                R.layout.popowindow_detl_customer, null);

        mPopWindow = new PopupWindow(contentView);
        mPopWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopWindow.setHeight( LinearLayout.LayoutParams.WRAP_CONTENT);

        contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupWidth = contentView.getMeasuredWidth();    //  获取测量后的宽度
        int popupHeight = contentView.getMeasuredHeight();  //获取测量后的高度
        int[] location = new int[2];
        TextView tv1 = (TextView) contentView.findViewById(R.id.customer_apo);
        TextView tv2 = (TextView) contentView.findViewById(R.id.custom_comm_log);
        TextView tv3 = (TextView) contentView.findViewById(R.id.customer_team);
        TextView tv5 = (TextView) contentView.findViewById(R.id.customer_operation_log);
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        tv5.setOnClickListener(this);
        img_more1.getLocationOnScreen(location);
        mPopWindow.setAnimationStyle(R.style.contextMenuAnim);
        mPopWindow.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.pop_bg));
        mPopWindow.setTouchable(true);
        mPopWindow.setOutsideTouchable(true);   //设置外部点击关闭ppw窗口
        mPopWindow.setFocusable(true);
        mPopWindow.update();

        mPopWindow.showAtLocation(img_more1, Gravity.NO_GRAVITY, (location[0] + img_more1.getWidth() / 2) - popupWidth / 2, location[1] - img_more1.getHeight()/2-popupHeight);

    }
    @Override
    protected void onRestart() {
        super.onRestart();
        customer =null;
        customer = GetCustumer.get();
        contact = GetContact.get();
        txt_title_name.setText(customer.getClient_name());
        if(ButtonTag2){
            fragment_base = new BaseFragment();
            manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_base).commitAllowingStateLoss();
        }else if (ButtonTag1){
            fragment_return_visit_record = new OtherBaseFragment();
            manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_return_visit_record).commitAllowingStateLoss();
        }else if (ButtonTag4){
            fragment_other = new OtherFragment();
            manager.beginTransaction().replace(R.id.usermee_frame_conner,fragment_other).commitAllowingStateLoss();
        }
    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            FloatingActionMenu v = leftCenterMenu;
            if (isShouldHideKeyboard(v, ev)) {
//                Toast.makeText(this, aBoolean+"", Toast.LENGTH_SHORT).show();
                if (leftCenterMenu.isOpen()){
                    leftCenterMenu.close(true);
                }
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 根据控件所在坐标和用户点击的坐标相对比，来判断是否隐藏，因为当用户点击控件时则不能隐藏
     *
     * @param v
     * @param event
     * @return
     */
    private boolean isShouldHideKeyboard(FloatingActionMenu v, MotionEvent event) {
        if (v != null ) {
            int[] l = {100, 100};
            int left = l[0],
                    top = l[1],
                    bottom = top ,
                    right = left ;
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击控件的事件，忽略它。
                return false;
            } else {
                return true;
            }
        }
        // 如果焦点不是控件则忽略，这个发生在视图刚绘制完，第一个焦点不在EditText上，和用户用轨迹球选择其他的焦点
        return false;
    }
}
